
clear 
clear matrix
clear mata

set maxvar 10000

use "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\BES2019_W23_Panel_v23.0.dta"

//// AUTHORITARIANISM PAPER VARIABLE LIST 

numlabel, add

/// personal income


recode p_gross_personalW7 (1/2=1 "Up to 9999") (3/4=2 "10 to 19999") (5/6=3 "20 to 29999") (7/8=4 "30 to 39999") (9/10=5 "40 to 49999") (11/12=6 "50 to 69999") (12/14=7 "70K and over") (15/16=8 "DK"), gen (incomerec7) 

recode p_gross_personalW10 (1/2=1 "Up to 9999") (3/4=2 "10 to 19999") (5/6=3 "20 to 29999") (7/8=4 "30 to 39999") (9/10=5 "40 to 49999") (11/12=6 "50 to 69999") (12/14=7 "70K and over") (15/16=8 "DK"), gen (incomerec10)

recode p_gross_personalW11 (1/2=1 "Up to 9999") (3/4=2 "10 to 19999") (5/6=3 "20 to 29999") (7/8=4 "30 to 39999") (9/10=5 "40 to 49999") (11/12=6 "50 to 69999") (12/14=7 "70K and over") (15/16=8 "DK"), gen (incomerec11)  

recode p_gross_personalW14 (1/2=1 "Up to 9999") (3/4=2 "10 to 19999") (5/6=3 "20 to 29999") (7/8=4 "30 to 39999") (9/10=5 "40 to 49999") (11/12=6 "50 to 69999") (12/14=7 "70K and over") (15/16=8 "DK"), gen (incomerec14) 


//// Education

/// Education

recode p_edlevelW7 (4/5=1) (0/3=0), gen (higheduc7)

recode p_edlevelW10 (4/5=1) (0/3=0), gen (higheduc10)

recode p_edlevelW11 (4/5=1) (0/3=0), gen (higheduc11)

recode p_edlevelW14 (4/5=1) (0/3=0), gen (higheduc)
rename higheduc higheduc14

//// Social grade

recode p_socgradeW7 p_socgradeW10 p_socgradeW11 p_socgradeW14 (8=.) 
recode p_socgradeW7 (7=.)


/// Age

sum ageW7 ageW10 ageW11 ageW14


///// Ethnicity 

recode p_ethnicityW7 (1/2=1 "White") (3/6=2 "Mixed") (7/10=3 "Asian") (11/13=4 "Black") (14=5 "Chinese") (15=6 "Other") (16=7 "DK"), gen (ethnicity7rec) 
recode p_ethnicityW10 (1/2=1 "White") (3/6=2 "Mixed") (7/10=3 "Asian") (11/13=4 "Black") (14=5 "Chinese") (15=6 "Other") (16=7 "DK"), gen (ethnicity10rec) 
recode p_ethnicityW11 (1/2=1 "White") (3/6=2 "Mixed") (7/10=3 "Asian") (11/13=4 "Black") (14=5 "Chinese") (15=6 "Other") (16=7 "DK"), gen (ethnicity11rec) 
recode p_ethnicityW14 (1/2=1 "White") (3/6=2 "Mixed") (7/10=3 "Asian") (11/13=4 "Black") (14=5 "Chinese") (15=6 "Other") (16=7 "DK"), gen (ethnicity14rec) 

recode p_ethnicityW7 (1=1 "White") (else=0), gen (ethnic7)
recode p_ethnicityW10 (1=1 "White") (else=0), gen (ethnic10)
recode p_ethnicityW11 (1=1 "White") (else=0), gen (ethnic11)
recode p_ethnicityW14 (1=1 "White") (else=0), gen (ethnic14)


recode auth1W7-auth4W7 (9999=.)
recode auth1W7 (2=1) (1=0), gen (auth1_W7)
recode auth2W7 (1=1) (2=0), gen (auth2_W7)
recode auth3W7 (2=1) (1=0), gen (auth3_W7)
recode auth4W7 (2=1) (1=0), gen (auth4_W7)

gen authW7=auth1_W7 + auth2_W7 + auth3_W7 + auth4_W7
gen authW701=authW7/4

tab auth1_W7

/// Wave 10

recode auth1W10-auth4W10 (9999=.)
recode auth1W10 (2=1) (1=0), gen (auth1_W10)
recode auth2W10 (1=1) (2=0), gen (auth2_W10)
recode auth3W10 (2=1) (1=0), gen (auth3_W10)
recode auth4W10 (2=1) (1=0), gen (auth4_W10)

gen authW10=auth1_W10 + auth2_W10 + auth3_W10 + auth4_W10
gen authW1001=authW10/4

/// Wave 11

recode auth1W11-auth4W11 (9999=.)
recode auth1W11 (2=1) (1=0), gen (auth1_W11)
recode auth2W11 (1=1) (2=0), gen (auth2_W11)
recode auth3W11 (2=1) (1=0), gen (auth3_W11)
recode auth4W11 (2=1) (1=0), gen (auth4_W11)

gen authW11=auth1_W11 + auth2_W11 + auth3_W11 + auth4_W11
gen authW1101=authW11/4

/// Wave 14

recode auth1W14-auth4W14 (9999=.)
recode auth1W14 (2=1) (1=0), gen (auth1_W14)
recode auth2W14 (1=1) (2=0), gen (auth2_W14)
recode auth3W14 (2=1) (1=0), gen (auth3_W14)
recode auth4W14 (2=1) (1=0), gen (auth4_W14)

gen authW14=auth1_W14 + auth2_W14 + auth3_W14 + auth4_W14
gen authW1401=authW14/4

//// DV1: Redistribution 

recode redistSelfW7 (9999=.)
recode redistSelfW10 (9999=.)
recode redistSelfW11 (9999=.)
recode redistSelfW14 (9999=.)

gen redistSelfW701=redistSelfW7/10
gen redistSelfW1001=redistSelfW10/10
gen redistSelfW1101=redistSelfW11/10
gen redistSelfW1401=redistSelfW14/10

//// DV2: Immigration scale

recode immigSelfW7 immigSelfW10 immigSelfW11 immigSelfW14 immigCulturalW7 immigCulturalW10 immigCulturalW11 immigCulturalW14 (9999=.)

pwcorr immigSelfW7 immigCulturalW7 
pwcorr immigSelfW10 immigCulturalW10 
pwcorr immigSelfW11 immigCulturalW11 
pwcorr immigSelfW14 immigCulturalW14 

alpha immigSelfW7 immigCulturalW7, item
alpha immigSelfW10 immigCulturalW10, item
alpha immigSelfW11 immigCulturalW11, item
alpha immigSelfW14 immigCulturalW14, item

factortest immigSelfW7 immigCulturalW7
factortest immigSelfW10 immigCulturalW10
factortest immigSelfW11 immigCulturalW11
factortest immigSelfW14 immigCulturalW14

factor immigSelfW7 immigCulturalW7

factor immigSelfW7 immigCulturalW7, factors(1)
rotate, oblimin

	local values "7 10 11 14"
	foreach value of local values {
    gen im_culturalW`value'=(immigCulturalW`value'-1)/6
}

gen immigSelfW701=immigSelfW7/10
gen immigSelfW1001=immigSelfW10/10
gen immigSelfW1101=immigSelfW11/10
gen immigSelfW1401=immigSelfW14/10

	local values "7 10 11 14"
	foreach value of local values {
    gen im_pref_2W`value'=(im_culturalW`value' + immigSelfW`value'01)/2
}

summ im_pref_2W7
summ im_pref_2W10
summ im_pref_2W11
summ im_pref_2W14

//// DV3: EU integration


tab EUIntegrationSelfW7
tab EUIntegrationSelfW10
tab EUIntegrationSelfW11
tab EUIntegrationSelfW14

recode EUIntegrationSelfW7 EUIntegrationSelfW10 EUIntegrationSelfW11 EUIntegrationSelfW14 (9999=.)

*Reverse code integration - bigger score = more European

gen EUintRW7=(0-EUIntegrationSelfW7)+10
gen EUintRW10=(0-EUIntegrationSelfW10)+10
gen EUintRW11=(0-EUIntegrationSelfW11)+10
gen EUintRW14=(0-EUIntegrationSelfW14)+10

	local values "7 10 11 14"
	foreach value of local values {
    gen eu_intW`value'=EUintRW`value'/10
}

////// DV4: PTV scores (3 WAVES ONLY)

//// Labour

recode ptvLabW7 ptvLabW10 ptvLabW11 (9999=.)

gen ptvLabW701=ptvLabW7/10
gen ptvLabW1001=ptvLabW10/10
gen ptvLabW1101=ptvLabW11/10


/// Conservative

recode ptvConW7 ptvConW10 ptvConW11 (9999=.)

gen ptvConW701=ptvConW7/10
gen ptvConW1001=ptvConW10/10
gen ptvConW1101=ptvConW11/10

//// UKIP

recode ptvUKIPW7 ptvUKIPW10 ptvUKIPW11 (9999=.)

gen ptvUKIPW701=ptvUKIPW7/10
gen ptvUKIPW1001=ptvUKIPW10/10
gen ptvUKIPW1101=ptvUKIPW11/10

/// Johnston et al. moderation: 

tab polAttentionW7

recode polAttentionW7 polAttentionW10 polAttentionW11 polAttentionW14 (9999=.)

*For random effects/hybrid models: 
gen polattW7=polAttentionW7/10
gen polattW10=polAttentionW10/10
gen polattW11=polAttentionW11/10
gen polattW14=polAttentionW14/10


/* 


// Political engagement: 
ageW7 ageW10 ageW11 ageW14
higheduc7 higheduc10 higheduc11 higheduc14
incomerec7 incomerec10 incomerec11 incomerec14 
p_socgradeW7 p_socgradeW10 p_socgradeW11 p_socgradeW14
p_ethnicityW7 p_ethnicityW10 p_ethnicityW1 p_ethnicityW14
leftRightW701 leftRightW1001 leftRightW1101 leftRightW1401
authW701 authW1001 authW1101 authW1401

DVS: redistSelfW701 redistSelfW1001 redistSelfW1101 redistSelfW1401
immigSelfW701 immigSelfW1001 immigSelfW1101 immigSelfW1401

ptvLabW701 ptvLabW1001 ptvLabW1101
ptvConW701 ptvConW1001 ptvConW1101
ptvUKIPW701 ptvUKIPW1001 ptvUKIPW1101


sum redistSelfW701 redistSelfW1001 redistSelfW1101 redistSelfW1401 immigSelfW701 immigSelfW1001 immigSelfW1101 immigSelfW1401 ptvLabW701 ptvLabW1001 ptvLabW1101 ptvConW701 ptvConW1001 ptvConW1101 ptvUKIPW701 ptvUKIPW1001 ptvUKIPW1101 */

rename  authW701  auth01W7 
rename  authW1001  auth01W10 
rename  authW1101 auth01W11 
rename  authW1401 auth01W14

rename  redistSelfW701 redistSelf01W7
rename   redistSelfW1001  redistSelf01W10
rename  redistSelfW1101  redistSelf01W11 
rename  redistSelfW1401 redistSelf01W14

rename  immigSelfW701  immigSelf01W7
rename  immigSelfW1001 immigSelf01W10
rename   immigSelfW1101  immigSelf01W11 
rename  immigSelfW1401 immigSelf01W14


rename  ptvLabW701  ptvLab01W7
rename  ptvLabW1001  ptvLab01W10 
rename  ptvLabW1101 ptvLab01W11

rename  ptvConW701   ptvCon01W7 
rename  ptvConW1001  ptvCon01W10 
rename  ptvConW1101 ptvCon01W11

rename  ptvUKIPW701  ptvUKIP01W7 
rename  ptvUKIPW1001  ptvUKIP01W10 
rename  ptvUKIPW1101 ptvUKIP01W11

 /// Restrict to the variables to use 
  
  save temp.dta, replace
  
  use temp.dta, clear
  
  tab eu_intW7
  
  keep id wave7 wave10 wave11 wave14 ageW7 ageW10 ageW11 ageW14 higheduc* incomerec* p_socgradeW7 p_socgradeW10 p_socgradeW11 p_socgradeW14  p_ethnicityW7 p_ethnicityW10 p_ethnicityW11 p_ethnicityW14 auth01* auth1_W* auth2_W* auth3_W* auth4_W* redistSelf01* immigSelf01W* ptvCon01* ptvUKIP01* ptvLab01* gender im_culturalW* im_pref* eu_intW* polattW* polAttentionW7 polAttentionW10 polAttentionW11 polAttentionW14
 
  // Generating standardized variables 
  

foreach var of varlist auth*7 auth*10 auth*11 auth*14 redistSelf01W7 redistSelf01W10 redistSelf01W11 redistSelf01W14 eu_intW7 eu_intW10 eu_intW11 eu_intW14 immigSelf01W7 immigSelf01W10 immigSelf01W11 immigSelf01W14 im_pref_2W7 im_pref_2W10 im_pref_2W11 im_pref_2W14 polattW7 polattW10 polattW11 polattW14 {
  summ `var'
  gen std_`var' = ((`var'-r(mean))/r(sd))
  }

  

  // data is in wide format
  
  duplicates report id
    drop if id==.
	
	 save temp.dta, replace
  
  
    use temp.dta, clear
  
  
  // Restructure long format
  
  
  
  reshape long wave ageW higheduc incomerec p_socgradeW p_ethnicityW leftRight01W std_auth01W auth01W std_auth1_W  auth1_W auth2_W std_auth2_W auth3_W std_auth3_W auth4_W std_auth4_W redistSelf01W std_redistSelf01W immigSelf01W std_immigSelf01W ptvCon01W ptvUKIP01W ptvLab01W im_econW im_culturalW im_pref_2W std_im_pref_2W eu_intW std_eu_intW polattW std_polattW polAttentionW, i(id) j(time)
  
 
  fre wave
  
   
  
    // Keep only people who are present at a given wave
	
	
  keep if wave==1
  
  
  
  
  
  
  
    // Set as panel data
  
  
  xtset id time
  
  
    // structure of the panel
	
	
  xtdes
  
  
  
  
  fre auth01W
  
  drop if auth01W==.
  
  
  
  
  
  xtdes

  	// N is  13085 - number of people in at least one of the four waves with non missing info on the authoritarianism var 
	
	d,s
	
		
	*Recode ethnicity: 

  recode p_ethnicityW (1=1 "white british") (else=0 "other"), gen(ethnic)
  
  tab ethnic
  tab p_ethnicityW
  

save "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RE and FE data.dta", replace

  
**# Preliminary analysis: attrition, RI-CLPM data prep, over-time variation in covariates


/// ATTRITION ANALYSIS
	
	sort id time
	
	// Generate observation variables:
	
	bysort id: gen obs = _n
	
	bysort id: egen totobs = count(obs)
	
	// Generate dummy variables: 
	
	ta gender, gen(gend)
	ta p_ethnicityW, gen(eth)
	ta incomerec, gen(inc)
	ta p_socgradeW, gen(soc)
	
	format gend1 ageW ///
	eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 eth11 eth12 eth13 eth14 eth15 eth16 ///
	higheduc inc1 inc2 inc3 inc4 inc5 inc6 inc7 inc8 soc1 soc2 soc3 soc4 soc5 soc6 ///
	leftRight01W auth01W redistSelf01W im_pref_2W ptvCon01W ptvUKIP01W ptvLab01W %9.2f

		//  full sample 
	tabstat gend1 ageW ///
	eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 eth11 eth12 eth13 eth14 eth15 eth16 ///
	higheduc inc1 inc2 inc3 inc4 inc5 inc6 inc7 inc8 soc1 soc2 soc3 soc4 soc5 soc6 ///
  auth01W redistSelf01W im_pref_2W eu_intW ptvCon01W ptvUKIP01W ptvLab01W , col(stat) f
	
  	//  observed more than once
  tabstat gend1 ageW ///
	eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 eth11 eth12 eth13 eth14 eth15 eth16 ///
	higheduc inc1 inc2 inc3 inc4 inc5 inc6 inc7 inc8 soc1 soc2 soc3 soc4 soc5 soc6 ///
	auth01W redistSelf01W im_pref_2W eu_intW ptvCon01W ptvUKIP01W ptvLab01W if totobs>1 , col(stat) f  

	 //// RI-CLPM CODING //// 
    
	   
  drop p_ethnicityW ptv* obs eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 eth11 eth12 eth13 eth14 eth15 eth16 inc1 inc2 inc3 inc4 inc5 inc6 inc7 inc8 soc1 soc2 soc3 soc4 soc5 soc6 std_polattW polattW

    
    reshape wide wave ageW higheduc incomerec p_socgradeW gender ethnic auth01W auth1_W auth2_W auth3_W auth4_W redistSelf01W immigSelf01W std_auth01W std_auth1_W std_auth2_W std_auth3_W std_auth4_W std_redistSelf01W std_immigSelf01W  im_econW im_culturalW im_pref_2W std_im_pref_2W eu_intW std_eu_intW polAttentionW, i(id) j(time)

	
  *For multiple group RI-CLPMs: 
tab auth01W7

gen polatt_v=polAttentionW7 if auth01W7!=.
replace polatt_v=polAttentionW10 if auth01W7==. & auth01W10!=. 
replace polatt_v=polAttentionW11 if auth01W7==. & auth01W10==. & auth01W11!=.
replace polatt_v=polAttentionW14 if auth01W7==. & auth01W10==. & auth01W11==. & auth01W14!=.

tab polatt_v
summ polatt_v, detail
gen polatt_group=0 if polatt_v<7
replace polatt_group=1 if polatt_v>7&polatt_v<11
tab polatt_group

summ polatt_v, detail
gen polatt_group2=0 if polatt_v<6
replace polatt_group2=1 if polatt_v>8&polatt_v<11
tab polatt_group2


  *Labels:
	tab ethnic7
	tab p_socgradeW7
	tab incomerec7
	
	label drop _all
 
	save "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data.dta", replace
	
	
drop if polatt_group==.
	
	tab polatt_group
	
		save "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data_attention.dta", replace
		
		
	tab polatt_group
	
	keep if polatt_group==1
		
		save "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data_attention_high.dta", replace
		
		use "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data_attention.dta", clear
		
		
	tab polatt_group
	
	keep if polatt_group==0		
		save "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data_attention_low.dta", replace
		
		*Ethnicity: 
		
			use "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data.dta", clear

tab ethnic7

gen ethnic_group=1 if ethnic7==1 & auth01W7!=.
replace ethnic_group=1 if ethnic10==1 & auth01W7==. & auth01W10!=.
replace ethnic_group=1 if ethnic11==1 & auth01W7==. & auth01W10==. & auth01W11!=.
replace ethnic_group=1 if ethnic14==1 & auth01W7==. & auth01W10==. & auth01W11==. & auth01W14!=.
replace ethnic_group=0 if ethnic7==0 & auth01W7!=.
replace ethnic_group=0 if ethnic10==0 & auth01W7==. & auth01W10!=.
replace ethnic_group=0 if ethnic11==0 & auth01W7==. & auth01W10==. & auth01W11!=.
replace ethnic_group=0 if ethnic14==0 & auth01W7==. & auth01W10==. & auth01W11==. & auth01W14!=.

		save "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data_ethnicity.dta", replace
		
		
		tab ethnic_group
		
		keep if ethnic_group==1
		
				save "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data_ethnicity_white.dta", replace
				
						use "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data_ethnicity.dta", clear
		
		tab ethnic_group
		
		keep if ethnic_group==0
		
			save "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data_ethnicity_nonwhite.dta", replace
			
					// WP variation in covariates
					
							   use "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RE and FE data.dta", clear	
		   
		    drop if auth01W==.|im_pref_2W==.|redistSelf01W==.|eu_intW==.
			
			keep auth01W im_pref_2W redistSelf01W eu_intW id time

 	
  reshape wide auth01W im_pref_2W redistSelf01W eu_intW, i(id) j(time)
  
 			
tab auth01W7	
bysort id: gen auth_chW10=1 if auth01W7<auth01W10
bysort id: replace auth_chW10=0 if auth01W7==auth01W10
bysort id: replace auth_chW10=-1 if auth01W7>auth01W10

bysort id: gen auth_chW11=1 if auth01W10<auth01W11
bysort id: replace auth_chW11=0 if auth01W10==auth01W11
bysort id: replace auth_chW11=-1 if auth01W10>auth01W11

bysort id: gen auth_chW14=1 if auth01W11<auth01W14
bysort id: replace auth_chW14=0 if auth01W11==auth01W14
bysort id: replace auth_chW14=-1 if auth01W11>auth01W14

tab auth_chW10
tab auth_chW11
tab auth_chW14			




use "C:\Replication files_Authoritarianism, Political Attitudes and Vote Choice\RICLPM data.dta", clear
	
tab ethnic7
gen ethnic_ch=1 if ethnic7==1&ethnic10==0
replace ethnic_ch=1 if ethnic7==0&ethnic10==1
replace ethnic_ch=1 if ethnic10==1&ethnic11==0
replace ethnic_ch=1 if ethnic10==0&ethnic11==1	
replace ethnic_ch=1 if ethnic11==1&ethnic14==0
replace ethnic_ch=1 if ethnic11==0&ethnic14==1			
		
		
	tab ethnic_ch
	tab ethnic10
	tab ethnic11 
	tab ethnic14
	
gen higheduc_ch=1 if higheduc7==1&higheduc10==0
replace higheduc_ch=1 if higheduc7==0&higheduc10==1
replace higheduc_ch=1 if higheduc10==1&higheduc11==0
replace higheduc_ch=1 if higheduc10==0&higheduc11==1	
replace higheduc_ch=1 if higheduc11==1&higheduc14==0
replace higheduc_ch=1 if higheduc11==0&higheduc14==1	

	tab higheduc_ch
	tab higheduc10
	tab higheduc11	
	tab higheduc14	
	
	
tab p_socgradeW7

gen soc_ch=.
local values "1 2 3 4 5 6"
	foreach value of local values {
    replace soc_ch=1 if p_socgradeW7==`value' & p_socgradeW7!=`value'
}

local values "1 2 3 4 5 6"
	foreach value of local values {
    replace soc_ch=1 if p_socgradeW10==`value' & p_socgradeW11!=`value'
}

local values "1 2 3 4 5 6"
	foreach value of local values {
    replace soc_ch=1 if p_socgradeW11==`value' & p_socgradeW14!=`value'
}


tab soc_ch


tab gender7
gen gender_ch=1 if (gender7==1 & gender10==2)|(gender7==2 & gender10==1)
replace gender_ch=1 if (gender10==1 & gender11==2)|(gender10==2 & gender11==1)
replace gender_ch=1 if (gender11==1 & gender14==2)|(gender11==2 & gender14==1)
		
		tab gender_ch

  
  
  
  
			 
			 
			 
			 
			
			
			
			
			 
			 
			 